package cn.lyq.card.ui.rank

import android.widget.ImageView
import cn.lyq.card.R
import cn.lyq.card.data.model.RankInfo
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder


class RankAdapter : BaseQuickAdapter<RankInfo, BaseViewHolder>
    (R.layout.item_rank, mutableListOf()) {

    override fun convert(holder: BaseViewHolder, item: RankInfo) {
        holder.setText(R.id.tvUserName, item.agentName ?: "代理")
        holder.setText(R.id.tvUserPhone, item.phone ?: "*****")
        holder.setText(R.id.tvValue, item.number ?: "**")
        //因为有header -1 , index + 1才是排名
        holder.setText(R.id.tvRank, holder.adapterPosition.toString())
        //因为有header -1
        holder.setGone(R.id.tvRank, holder.adapterPosition <= 3)
        holder.setGone(R.id.imgRank, holder.adapterPosition > 3)
        val src = when (holder.adapterPosition - 1) {
            0 -> R.drawable.ic_rank1
            1 -> R.drawable.ic_rank2
            else -> R.drawable.ic_rank3
        }
        holder.getView<ImageView>(R.id.imgRank).setImageResource(src)

        holder.setGone(R.id.tvShadow, holder.adapterPosition != itemCount - 1)
    }

}